// src/utils/request.ts
import axios from 'axios'

const instance = axios.create({
  baseURL: '/api',
  timeout: 5000,
})

//延迟获取 store
instance.interceptors.request.use(config => {
  const { useUserStore } = require('@/stores/userStore')  // 用 require 避免 import 提前执行
  const store = useUserStore()
  if (store.token) {
    config.headers.Authorization = `Bearer ${store.token}`
  }
  return config
})

export default instance
